<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/myStrategyComment.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/jquery-confirm/css/jquery-confirm.css">
    <script src="/js/plugins/jquery-confirm/js/jquery-confirm.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/plugins/eleditor/Eleditor.min.js"></script>
    <script src="/js/plugins/eleditor/webuploader.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>

    <script>
        $(function () {

            var userStr = sessionStorage.getItem("user");
            var userJSON;
            var params = getParams();
            if (params.id) {
                //回显该攻略的所有标签
                $.get("/strategies/" + params.id + "/tags", {pageSize: 0}, function (data) {
                    $("#forLoop").renderValues(data);
                });

                //将攻略id添加到表单
                $("#strategyId").val(params.id);
            }
            if (userStr) {
                //将评论人id添加到表单
                userJSON = JSON.parse(userStr);
                $("#commentatorId").val(userJSON.id);
            }

            //指定评论为攻略类型
            $("#type").val(0);

            //对星级的操作
            $(".star .fa-lg").click(function () {
                var num = $(this).data("num");
                $("#star").val(num);
                $.each($(".star .fa-lg"), function (index, ele) {
                    if ($(ele).data("num") <= num) {
                        $(ele).attr("class", "fa fa-star fa-lg")
                    } else {
                        $(ele).attr("class", "fa fa-star-o fa-lg")
                    }
                })
            });


            //移动富文本框插件
            var Edr = new Eleditor({
                el: '#contentEditor',
                upload: {
                    //图片上传的服务器接口
                    server: '/images',
                    //修改图片接收参数的名称
                    formName: 'pic'
                },
            });

            //params.push({name: "content", value: Edr.getContent()})

            //保存选择的标签数组,动态绑定事件函数
            var ids = [];
            $("#forLoop").on("click", ":checkbox", function () {
                ids.push($(this).val());
            });


            $("#submitBtn").click(function () {
                //保存文本框数据
                $("#content").val(Edr.getContent());
                $("#ids").val(ids);
                $("#commentForm").ajaxSubmit(function (data) {
                    if (data.success) {
                        $(document).dialog({
                            type : 'confirm',
                            style: 'IOS',
                            titleShow: false,
                            content: '发布成功!',
                            buttons: [
                                {
                                    name: '确定',
                                    callback: function() {
                                        //window.location.href="/strategyCatalogs.html?id="+params.id;
                                        window.location.href=reload();
                                    }
                                }

                            ]
                        });
                    }

                })
            });
            /*

                            $("#submitBtn").ajaxSubmit({
                                    //表单提交前执行的函数
                                    //params表单参数数组-----Form表单中相关的参数封装成数组对象
                                    //Jquery的form表单
                                    //options表单的详细配置
                                    beforeSubmit: function (params, form, options) {
                                        //在表单提交之前 将缺少的的参数添加到参数列表中

                                    },
                                    success:function (data) {
                                        if(data.success){
                                            window.location.href="/strategyCatalogs.html";
                                        }
                                    }
                                }
                            )
            */

        })
    </script>


</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:window.history.go(-1)">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>

        </div>
        <div class="col">
            <span>点评</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<div class="comment">
    <div class="container star">
        <p>你对该旅游地的评价</p>
        <i class="fa fa-star-o fa-lg" data-num="1"></i>
        <i class="fa fa-star-o fa-lg" data-num="2"></i>
        <i class="fa fa-star-o fa-lg" data-num="3"></i>
        <i class="fa fa-star-o fa-lg" data-num="4"></i>
        <i class="fa fa-star-o fa-lg" data-num="5"></i>
    </div>
    <hr/>
    <div class="container tag">

        <form id="commentForm" method="post" action="/strategies/strategyComments">
            <input type="hidden" id="strategyId" name="releasedDetail.id"/>
            <input type="hidden" id="commentatorId" name="commentator.id"/>
            <input type="hidden" id="type" name="type"/>
            <input type="hidden" id="star" name="star"/>
            <input type="hidden" id="content" name="content"/>
            <input type="hidden" id="ids" name="ids"/>
            <input type="hidden" id="imgUrl" name="imgUrl"/>
            <p>请为该旅游地选择合适的标签（大家都在评）</p>
            <div id="forLoop">
                <div class="btn-group-toggle" data-toggle="buttons" render-loop="list">
                    <label class="btn btn-outline-danger">
                        <input type="checkbox" autocomplete="off" render-value="list.tagId"><label
                            render-html="list.tagName"></label>
                    </label>
                </div>
            </div>
            <p>添加你自己的标签</p>
            <textarea name="myTags" class="form-control" placeholder="请使用空格隔开标签，每个标签不超8个字"></textarea>
            <!--<input name="myTags" class="form-control"  placeholder="请使用空格隔开标签，每个标签不超8个字"   />-->
        </form>
        <p>更多评价内容</p>
        <div id="contentEditor" name="content">
        </div>

        <div class="operation">
            <button class="btn" onclick="window.history.go(-1)">放弃评价</button>
            <button class="btn" id="submitBtn">提交评价</button>
        </div>
    </div>
</div>
</body>


</html>